package adv7;

import java.io.*;
import java.util.*;

public class CompanyTest {

	public static void main(String[] args) {

		Company c = null;
		ObjectOutputStream oos = null;
		ObjectInputStream ois = null;
		try {
			// 反序列化 强转
			ois = new ObjectInputStream(new FileInputStream("company.info"));
			c = (Company) ois.readObject();
			ois.close();// 获得上次保存的公司信息
		} catch (Exception e) {
			System.out.println("没有公司的以前的信息");
		}
		if (c == null) {
			c = new Company("阿里巴巴集团有限公司", "浙江省杭州市", "8888888");
		}

		SaveThread s = new SaveThread(c);
		s.start();

		Scanner in = new Scanner(System.in);
		while (true) {
			System.out
					.println("1.招聘员工     2.查看员工信息     3.辞退员工     4.公司信息      5.公司人数      6.退出");
			int num = in.nextInt();
			switch (num) {
			case 1:
				System.out.println("请输入要招聘的员工的姓名，性别，职务，薪水、工号，年龄:");
				String name = in.next();
				String sex = in.next();
				String position = in.next();
				String salary = in.next();
				String workNum = in.next();
				int age = in.nextInt();
				Employees e = new Employees(name, sex, workNum, age);
				boolean f = c.addCompany(e);
				if (f == true) {
					System.out.println("添加成功！！！");
				} else {
					System.out.println("添加失败！！！");
				}
				break;

			case 2:
				c.show();
				break;

			case 3:
				System.out.println("请输入辞退的员工工号：");
				String num1 = in.next();
				boolean flag = c.dismiss(num1);
				if (flag == true) {
					System.out.println("删除成功！！！");
				} else {
					System.out.println("没有此员工！！！");
				}
				break;

			case 4:
				c.showInfo();

				break;
			case 5:
				c.count();
				break;
			case 6:
				// 保存公司的信息

				try {
					oos = new ObjectOutputStream(new FileOutputStream(
							"company.info"));
					// // 对象序列化 写入流
					oos.writeObject(c);
					oos.close();// 写在一起的话 oos提前关闭
				} catch (Exception e1) {
					// TODO 自动生成的 catch 块
					// e1.printStackTrace();
				}

				System.out.println("退出成功！！！！");
				return;
			}
		}
	}

}
